package myTest;


import java.util.Base64;

public class BASE64UrlTest {


    public static void main(String[] args) {
        String s = "zhang li wang {xxxx:yyy}dfgdJ@SDF45155$&*^*@098@*(7的身份解开了士大夫 412542345641";
        System.out.println("原字符串：" + s);
        String encryptString = Base64.getUrlEncoder().encodeToString(s.getBytes());
        System.out.println("加密后：" + encryptString);
        System.out.println("加密后：" + Base64.getEncoder().encodeToString(s.getBytes()));
        System.out.println("解密后：" + decryptBASE64(encryptString));
    }

    /**
     * BASE64解密
     *
     * @param key
     * @return
     * @throws Exception
     */
    public static String decryptBASE64(String key) {
        byte[] bt;
        bt = Base64.getUrlDecoder().decode(key);
        return new String(bt);

    }

}
